﻿using BLL;
using DAL;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Metro;
using DevExpress.XtraNavBar;
using Model;
using SqlSugar.Extensions;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using Tools;
using 后整理管理系统.入库管理.配件入库;
using 后整理管理系统.出库管理;
using 后整理管理系统.出库管理.原料出库;
using 后整理管理系统.基本资料;
using 后整理管理系统.报表窗体;
using 后整理管理系统.自定义类;
using 纺织贸易管理系统.其他窗体;
using 纺织贸易管理系统.出库管理;
using 纺织贸易管理系统.基本资料;
using 纺织贸易管理系统.报表窗体;
using 纺织贸易管理系统.新增窗体;
using 纺织贸易管理系统.设置窗体;
using 纺织贸易管理系统.选择窗体;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace 纺织贸易管理系统
{
    public  partial  class Main :Form 
    {
        private List<MenuTable> menuTables;
        private string res = string.Empty;
        private decimal totalJingchang = 0;
        private decimal totalchuchang = 0;
        private decimal totaldajuan = 0;
        public Main()
        {
            MainForm.mainform = this;
            //Connect.Environmen = "公司";
            //Connect.GetColumntable();
            InitializeComponent();
            timer1.Start();
            label1.Text ="正在统计";
            label2.Text = "正在统计";
            label3.Text = "正在统计";
          
            //创建菜单
            CreatFatherMenu();
            label4.Text  = "欢迎" + CurrentUser.user.YHMC ;
            Task.Run(new Action(() => {
               
             GetAccess.GetUserAccess(CurrentUser.user.YHBH );
            
           
            var settings = Connect.GetSugar().Queryable<Setting>().ToList();
            QueryTime.间隔 = Convert.ToInt32 ( SettingService.GetSetting (new Model.Setting() { formname = "", settingname = "时间间隔", settingValue ="" }).settingValue) ;
            string settingvalue = SettingService.GetSetting(new Model.Setting() { formname = "", settingname = "数量小数位", settingValue = "" }).settingValue;
            QueryTime.Digit = Convert.ToInt32(settingvalue == string.Empty ? "1" : settingvalue);
            QueryTime.DefaultStock = SettingService.GetSetting(x=>x.settingname== "默认仓库").settingValue;
            string maxrow = SettingService.GetSetting(x => x.settingname == "MaxRow").settingValue;
            QueryTime.自动填写工序 = SettingService.GetSetting(x => x.settingname == "工序选择填写").settingValue;
            QueryTime.自动填写工序 = string.IsNullOrEmpty(QueryTime.自动填写工序) ? "是" : QueryTime.自动填写工序;
            BLL.库存BLL.ClearStockRull =SettingService.GetSetting(x => x.settingname == "库存清理规则").settingValue ;
            if (string.IsNullOrWhiteSpace(maxrow))
            {
                QueryTime.Maxrow = 10;
            }
            else
            {
                if (maxrow == "0")
                {
                    QueryTime.Maxrow = 10;
                }
                else
                {
                    QueryTime.Maxrow = maxrow.ToInt();
                }
            }
            // ------------------------
            string maxcol = SettingService.GetSetting(x => x.settingname == "MaxCol").settingValue;
            if (string.IsNullOrWhiteSpace(maxcol))
            {
                QueryTime.Maxcol = 7;
            }
            else
            {
                if (maxcol == "0")
                {
                    QueryTime.Maxcol = 7;
                }
                else
                {
                    QueryTime.Maxcol = maxcol .ToInt();
                }
            }
            QueryTime.DefaultShippingMark =  SettingService.GetSetting(x => x.settingname == "默认唛头").settingValue;
            QueryTime.PrintRule=string.IsNullOrWhiteSpace( SettingService.GetSetting(x => x.settingname == "打印规则").settingValue)?PrintRuleStyle.SaveFirst : SettingService.GetSetting(x => x.settingname == "打印规则").settingValue;
            QueryTime.IsCalGive = string.IsNullOrWhiteSpace(SettingService.GetSetting(x => x.settingname == "计算赠送").settingValue) ? true : false;
            QueryTime.IsMustNeedTel= SettingService.GetSetting(x => x.settingname == "强制电话").settingValue=="是";
            QueryTime.ManualInventoryClearance = settings.FirstOrDefault(x=>x.settingname== "手工清库存")==null?false : settings.FirstOrDefault(x => x.settingname == "手工清库存").settingValue=="True";
            Tools.打印横版码单.IsCalGiveLength = QueryTime.IsCalGive;
            QueryTime.DefaultTitle = infoService.Getinfolst()[0].gsmc;
               
            }));
            //Console.WriteLine("创建原料信息表");
            //var db = new SQLHelper.SqlSugor();
            //db.CreatTable<RawMaterial>(new SQLHelper.TableInfo() { CharLength = 260, IsDBNull = false, Isidentity = false, PrimaryKey = "ID" });
            //Console.WriteLine("创建入库细码表成功");
            //Console.WriteLine("创建辅料单据表");
            //db.CreatTable<AccessoriesInfo>(new SQLHelper.TableInfo() { CharLength = 260, IsDBNull = false, Isidentity = false, PrimaryKey = "ID" });
            //Console.WriteLine("创建辅料单据表成功");
            //Console.WriteLine("创建原料单据表");
            //db.CreatTable<ImportAndExportOfRawMaterials>(new SQLHelper.TableInfo() { CharLength = 260, IsDBNull = false, Isidentity = false, PrimaryKey = "ID" });
            //Console.WriteLine("创建原料单据表成功");
        }
        /// <summary>
        /// 创建菜单
        /// </summary>
        public  void CreatFatherMenu()
        {
            navBarControl1.Groups.Clear();
            var fathermenu = FatherMenuTableService.GetFatherMenuTablelst(x=>x.UserID==CurrentUser.user.YHBH ).Where(x=>x.Visiable==true ).ToList ();
            menuTables = MenuTableService.GetMenuTablelst();
            foreach (FatherMenuTable f in fathermenu)
            {
                DevExpress.XtraNavBar.NavBarGroup group = new DevExpress.XtraNavBar.NavBarGroup
                {
                    Name = f.FatherMenuName,
                    Caption = f.FatherMenuName,
                    SmallImage = global::后整理管理系统.Properties.Resources.BOFolder_16x16 
                };
                this.navBarControl1.Groups.Add(group);
                //group.Expanded = true;
                CreatMenu(f.FatherMenuName ,group );
            }
        }
        //创建子菜单
      private void CreatMenu(string fathermenu,NavBarGroup group)
        {
            foreach (MenuTable m in menuTables.Where<MenuTable >(x=>x.FatherMenu==fathermenu&&x.Visitable==true &&x.UserID==CurrentUser.user.YHBH ).GroupBy(x => x.MenuName ).Select(x => x.First()).ToList())
            {
                var item = new NavBarItem() { Caption = m.MenuName, Name = m.FormName };
                item.ImageOptions.SmallImage = global::后整理管理系统.Properties.Resources.notes_16x16;
                group.ItemLinks.Add(new NavBarItemLink(item));
            }
        }
        

        private void navBarControl1_LinkClicked(object sender, NavBarLinkEventArgs e)
        {
          var menu=  MenuTableService.GetOneMenuTable(x => x.MenuName == e.Link.Caption);
            if (menu.FormName != "")
            {
                switch (menu.FormName )
                {
                    case "费用报销单":
                     if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        {
                            CheckTab(new 费用报销列表 () { Text = menu.MenuName + "列表" });
                        }
                        else
                        {
                            CheckTab(new 采购查询());
                        }
                        break;
                    case "账户管理":
                        CheckTab(new 账户资料 ());
                        break;
                    case "色卡库存":
                        CheckTab(new 色卡库存 ());
                        break;
                    case "仓库调拨单":
                        CheckTab(new 库存调拨单查询());
                        break;
                    case "经轴信息":
                        CheckTab(new 码单());
                        break;
                    case "打样工艺单":
                        CheckTab(new 打样管理());
                        break;
                    case "重新建账":
                        new 输入密码().ShowDialog();
                        break;
                    case "用户管理":
                        CheckTab(new 用户管理());
                        break;
                    case "公司信息":
                        CheckTab(new 公司信息());
                        break;
                    case "菜单管理":
                        CheckTab(new 菜单管理());
                        break;
                    case "权限管理":
                        CheckTab(new 权限管理());
                        break;
                    case "坯布日产量":
                        CheckTab(new 坯布日产量统计());
                        break;
                    case "门市采样单":
                        CheckTab(new 门市采样统计());
                        break;
                    case "品种资料":
                        CheckTab(new 品种资料());
                        break;
                    case "寄件列表":
                        CheckTab(new 寄件列表 ());
                        break;
                    case "打样管理":
                        CheckTab(new 打样管理());
                        break;
                    case "原料信息":
                        CheckTab(new 原料信息());
                        break;
                    case "原料库存":
                        CheckTab(new 原料库存());
                        break;
                    case "原料入库列表":
                        CheckTab(new 原料入库列表());
                        break;
                    case "原料领用列表":
                        CheckTab(new 原料领用列表());
                        break;
                    case "原料盘亏列表":
                        CheckTab(new 原料盘亏列表());
                        break;
                    case "原料盘盈列表":
                        CheckTab(new 原料盘盈列表());
                        break;
                    case "原料采购退货列表":
                        CheckTab(new 原料退货列表());
                        break;
                    case "细码库存":
                        CheckTab(new 细码库存());
                        break;
                    case "采购入库单":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        {
                            CheckTab(new 采购单列表() { Text =menu.MenuName + "列表" });
                        }
                        else
                        {
                            CheckTab(new 采购查询());
                        }
                        break;
                    case "客户资料":
                        CheckTab(new 客户资料());
                        break;
                    case "供货商资料":
                        CheckTab(new 供货商资料());
                        break;
                    case "库存查询":
                        CheckTab(new 库存报表());
                        break;
                    case "委外加工单":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        {
                            CheckTab(new 委外加工单列表() { Text = menu.MenuName + "列表" });
                        }
                        else
                        {
                            CheckTab(new 委外加工查询());
                        }
                            break;
                    case "委外取货单":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 委外取货列表() { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 委外取货查询());
                        }
                        break;
                    case "销售退货单":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 销售退货列表() { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 销售退货查询());
                        }
                        break;
                    case "销售计划单":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 销售订单查询() { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 销售计划单查询());
                        }
                        break;
                    case "员工资料":
                        CheckTab(new 员工管理());
                        break;
                    case "物流资料":
                        CheckTab(new 物流管理());
                        break;
                    case "架子资料":
                        CheckTab(new 架子资料 ());
                        break;
                    case "仓库资料":
                        CheckTab(new 仓库信息());
                        break;
                    case "支架资料":
                        CheckTab(new 支架信息());
                        break;
                    case "色号资料":
                        CheckTab(new 色号资料());
                        break;
                    case "盘盈入库单":
                        CheckTab(new 盘盈入库查询());
                        break;
                    case "盘亏出库单":
                        CheckTab(new 盘亏出库查询());
                        break;
                    case "寄样记录分析":
                        CheckTab(new 寄样统计());
                        break;
                    case "寻找样布":
                        CheckTab(new 寻找样布());
                        break;
                    case "员工管理":
                        CheckTab(new 员工管理());
                        break;
                    case "唛头关联":
                        CheckTab(new 唛头关联());
                        break;
                    case "销售发货单":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 销售发货列表() { Text = "成品出仓列表" }); }
                        else
                        {
                            CheckTab(new 销售发货单查询());
                        }
                        break;
                    case "打卷报表":
                        CheckTab(new 打卷报表());
                        break;
                    case "生产指示单":
                        CheckTab(new 生产计划单查询());
                        break;
                    case "疵点管理":
                        CheckTab(new 疵点信息());
                        break;
                    case "产量报表":
                        CheckTab(new 产量报表 ());
                        break;
                    case "产量统计":
                        CheckTab(new 产量统计());
                        break;
                    case "应收款管理":
                        CheckTab(new 应收款查询());
                        break;
                    case "应付款管理":
                        CheckTab(new 应付款查询());
                        break;
                    case "采购退货单":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 采购退货列表() { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 采购退货查询());
                        }
                        break;
                    case "开具发票":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        {
                            CheckTab(new 发票开具列表() { Text = menu.MenuName + "列表" });
                        }
                        else
                        {
                            CheckTab(new 发票开具查询());
                        }
                        break;
                    case "发票签收":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        {
                            CheckTab(new 发票签收列表() { Text = menu.MenuName + "列表" });
                        }
                        else
                        {
                            CheckTab(new 发票签收查询());
                        }
                        break;
                    case "采购通知单":
                        CheckTab(new 采购通知单查询());
                        break;
                    case "流转卡管理":
                        CheckTab(new 流程卡查询());
                        break;
                    case "生产入库单":
                        CheckTab(new 来货入库 () { Text = "单布进仓列表" });
                        break;
                    case "销售客诉列表":
                        CheckTab(new 销售客诉单列表());
                        break;
                    case "原料销售列表":
                        CheckTab(new 原料销售列表());
                        break;
                    case "辅料销售列表":
                        CheckTab(new 辅料销售列表());
                        break;
                    case "工艺信息":
                        CheckTab(new 工艺信息 ());
                        break;
                    case "机台信息":
                        CheckTab(new 岗位信息 ());
                        break;
                    case "发货通知单":
                        CheckTab(new 发货通知单查询());
                        break;
                    case "退货申请单":
                        CheckTab(new 退货申请单查询());
                        break;
                    case "来样管理":
                        CheckTab(new 来样报价查询());
                        break;
                    case "色卡采购":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 色卡采购列表 () { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 色卡采购列表 ());
                        }
                        break;
                    case "色卡销售":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 色卡销售列表() { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 色卡销售列表());
                        }
                        break;
                    case "色卡盘盈":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 色卡盘盈列表() { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 色卡盘盈列表());
                        }
                        break;
                    case "色卡盘亏":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 色卡盘亏列表 () { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 色卡盘亏列表());
                        }
                        break;
                    case "生产退卷查询":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 生产退仓查询 () { Text = "单布退仓列表" }); }
                        else
                        {
                            CheckTab(new 生产退仓查询());
                        }
                        break;
                    case "成品登记":
                        if (系统设定.GetSet(new Model.Setting() { formname = "", settingname = "订单显示样式", settingValue = "列表样式" }).settingValue == "清单样式")
                        { CheckTab(new 成品登记列表  () { Text = menu.MenuName + "列表" }); }
                        else
                        {
                            CheckTab(new 成品登记列表 ());
                        }
                        break;
                    case "排产单列表":
                       CheckTab(new 排产单列表()); 
                        break;
                    case "销售预出库列表":
                        CheckTab(new 销售预出库列表());
                        break;
                    case "配件采购列表":
                        CheckTab(new 配件采购列表());
                        break;
                    case "检测报表":
                        CheckTab(new 检测报表());
                        break;
                    case "原料领用计划列表":
                        CheckTab(new 原料领用计划列表());
                        break;
                }
            }
        }
        //检查有没有一样的窗体
        private void CheckTab(Form form)
        {
            if (BLL.AccessBLL.CheckAccess(form.Text ))
            {
                foreach (SuperTabItem page in superTabControl1.Tabs)
                {
                    if (page.Text == form.Text)
                    {
                        superTabControl1.SelectedTab = page;
                        return;
                    }

                }
                AddMidForm(form);
            }
            else
            {
                ShowMessageBox.ShowErrorBox ( "您没有使用该功能的权限！请让管理员为你开通");
            }
        }
        /// <summary>
        /// 把窗体添加到tab里面
        /// </summary>
        /// <param name="form">窗体类</param>
        public void AddMidForm(Form form )
        {
            try
            {
                SuperTabItem page = superTabControl1.CreateTab(form.Name);
                form.Dock = DockStyle.Fill;
                form.FormBorderStyle = FormBorderStyle.None;
                form.WindowState = FormWindowState.Maximized;
                form.TopLevel = false;
                page.Name = form.Text;
                page.Text = form.Text;
                page.AttachedControl.Controls.Add(form);
                superTabControl1.Tabs.Add(page);
                superTabControl1.SelectedTab = page;
                form.Show();
            }
            catch (Exception ex)
            {
                AlterDlg.Show(ex.Message);
            }
            //try
            //{
            //    Sunny.UI.UIPage   page =new Sunny.UI.UIPage  ();              
            //    form.FormBorderStyle = FormBorderStyle.None;
            //    form.WindowState = FormWindowState.Maximized;
            //    form.TopLevel = false;
            //    page.Name = form.Text;
            //    page.Text = form.Text;  
            //    form.Dock = DockStyle.Fill;             
            //    form.Visible =true ;
            //    page.Dock = DockStyle.Fill;
            //    page.Controls.Add(form);
            //    uiTabControl1.AddPage (page);
            //    uiTabControl1.SelectPage(uiTabControl1.TabPages.Count -1);               
            //}
            //catch (Exception ex)
            //{
            //    AlterDlg.Show(ex.Message);
            //}
        }

        private void Main_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Hide();
            Task.WaitAll(DAL.TaskService.tasklist.ToArray ());
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            Task.Run(new Action(() =>
            {
                try
                {
                    totalJingchang = Connect.GetSugar().Queryable<danjumingxitable>().Where(x => x.rq >= DateTime.Now.Date && x.danhao.StartsWith("SC")).Sum(x => x.chengpingmishu);
                    totalchuchang = Connect.GetSugar().Queryable<danjumingxitable>().Where(x => x.rq >= DateTime.Now.Date && x.danhao.StartsWith("F20")).Sum(x => x.toupimishu);
                    totaldajuan = Connect.GetSugar().Queryable<JuanHaoTable>().Where(x => x.rq >= DateTime.Now.Date).Sum(x => x.MiShu);
                }
                catch
                {
                    timer1.Stop();
                }
            }));
            label1.Text = $"{totalJingchang.ToString("N2")}米";
            label2.Text = $"{totalchuchang.ToString("N2")}米";
            label3.Text = $"{totaldajuan.ToString("N2")}米";
        }

        private void Main_Load(object sender, EventArgs e)
        {
           
            //Connect.dbcontext.CodeFirst.SetStringDefaultLength(500/*设置varchar默认长度为200*/).InitTables(typeof(ManualCode));
            Task.Run(new Action(() => { Tools.ReportService.DownLoadMarks(Application.StartupPath); }));
            //SELECT  CONVERT(date, rq) AS 统计日期, sum(chengpingmishu) AS 数量 FROM danjumingxitable WHERE  rq >= DATEADD(day, -7, GETDATE()) and danhao like 'SC%' GROUP BY  CONVERT(date, rq) ORDER BY  统计日期 ASC
            try
            {
                label5.Text  = QueryTime.DefaultTitle ;
                InitJingchangChat();
                InitJingchangChat2();
                InitJingchangChat3();
               
            }
            catch (Exception ex) 
            {
                ShowMessageBox.ShowErrorBox("初始化图表失败：" + ex.Message);
            }
        }

        private void InitJingchangChat3()
        {
            chart3.Series.Clear();
            var jingchangdt = Connect.GetSugar().Ado.GetDataTable("SELECT  CONVERT(date, rq) AS 统计日期, sum(biaoqianmishu) AS 数量 FROM juanhaotable WHERE  rq > DATEADD(day, -7, GETDATE())  AND RQ < CONVERT(date, GETDATE())  GROUP BY  CONVERT(date, rq) ORDER BY  统计日期 ASC");
            var series = new Series("数量");
            series.ChartType = SeriesChartType.Column;
            // 设置悬停提示格式
            series.ToolTip = "日期: #VALX\n数量: #VALY";  // 使用内置变量占位符
            //series.IsValueShownAsLabel = false;  // 关闭默认标签显示
            // 绑定数据
            foreach (DataRow row in jingchangdt.Rows)
            {
                series.Points.AddXY(
                    Convert.ToDateTime(row["统计日期"]).ToString("MM-dd"),
                    Convert.ToInt32(row["数量"]));
            }
            chart3.Series.Add(series);
        }

        private void InitJingchangChat2()
        {
            chart2.Series.Clear();
            var jingchangdt = Connect.GetSugar().Ado.GetDataTable(
                "SELECT  CONVERT(date, rq) AS 统计日期, sum(chengpingmishu) AS 数量 FROM danjumingxitable" +
                " WHERE  rq > DATEADD(day, -7, GETDATE())  AND RQ < CONVERT(date, GETDATE()) and danhao like 'F20%' GROUP BY  CONVERT(date, rq) ORDER BY  统计日期 ASC");
            var series = new Series("数量");
            series.ChartType = SeriesChartType.Column;
            // 设置悬停提示格式
            series.ToolTip = "日期: #VALX\n数量: #VALY";  // 使用内置变量占位符
            //series.IsValueShownAsLabel = false;  // 关闭默认标签显示
            // 绑定数据
            foreach (DataRow row in jingchangdt.Rows)
            {
                series.Points.AddXY(
                    Convert.ToDateTime(row["统计日期"]).ToString("MM-dd"),
                    Convert.ToInt32(row["数量"]));
            }
            chart2.Series.Add(series);
        }

        /// <summary>
        /// 显示进仓统计
        /// </summary>
        private void InitJingchangChat()
        {
            chart1.Series.Clear();
            var jingchangdt = Connect.GetSugar().Ado.GetDataTable("SELECT  CONVERT(date, rq) AS 统计日期, sum(chengpingmishu) AS 数量 FROM danjumingxitable WHERE  rq >= DATEADD(day, -7, GETDATE())  AND RQ < CONVERT(date, GETDATE()) and danhao like 'SC%' GROUP BY  CONVERT(date, rq) ORDER BY  统计日期 ASC");
           
            var series = new Series("数量");
            series.ChartType = SeriesChartType.Column;
            // 设置悬停提示格式
            series.ToolTip = "日期: #VALX\n数量: #VALY";  // 使用内置变量占位符

            // 绑定数据
            foreach (DataRow row in jingchangdt.Rows)
            {
                series.Points.AddXY(
                    Convert.ToDateTime(row["统计日期"]).ToString("MM-dd"),
                    Convert.ToInt32(row["数量"]));
            }
            chart1.Series.Add(series);            
        }
        private void Main_HelpButtonClick(object sender, EventArgs e)
        {
            var fm = new 关于窗体();
            fm.ShowDialog();
        }

        private void superTabControl1_TabItemClose(object sender, SuperTabStripTabItemCloseEventArgs e)
        {
            SuperTabItem tab = e.Tab as SuperTabItem;
            var frms = this.superTabControl1.SelectedPanel.Controls.Find(tab.Text, false);
            if (frms.Length > 0)
            {
                Form frm = frms[0] as Form;
                var menutable = MenuTableService.GetOneMenuTable(x => x.FormName == frm.Name);
                if (menutable.FormName != "")
                {
                    var res = !this.ShowAskDialog("您确定要关闭该页面吗？\n确定关闭按确定。否则按取消");
                    e.Cancel = res;
                }
            }
        }

        private void 关闭所有选项卡ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                int tabs = superTabControl1.Tabs.Count;
                string[] tabsname = new string[tabs];
                for (int it = 0; it < tabs; it++)
                {
                    tabsname[it] = superTabControl1.Tabs[it].Name.ToString();
                }
                for (int it = 0; it < tabs; it++)
                {
                    if (it != 0)
                        superTabControl1.Tabs.Remove(tabsname[it]);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {
            Task.Run(new Action(() => { Tools.ReportService.DownLoad(Application.StartupPath);ShowMessageBox.ShowSuccess("同步完成"); }));
        }
        public void  CloseTab()
        {
            try
            {
                // 获取当前选中的 Tab
                SuperTabItem selectedTab = superTabControl1.SelectedTab;

                if (selectedTab != null)
                {
                    // 从 SuperTabControl 中移除当前 Tab
                    superTabControl1.Tabs.Remove(selectedTab);

                    // 释放资源（可选）
                    selectedTab.Dispose();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void uiImageButton1_Click(object sender, EventArgs e)
        {
            if (AccessBLL.CheckAccess("新增来货入库单"))
            {
                MainForm.mainform.AddMidForm(new 来货入库单() { Useful = FormUseful.新增 });
            }
        }

        private void uiImageButton2_Click(object sender, EventArgs e)
        {
            CheckTab(new 库存报表());
        }

        private void uiImageButton3_Click(object sender, EventArgs e)
        {
            if(AccessBLL.CheckAccess("新增发货单"))
            {
                MainForm.mainform.AddMidForm(new 销售发货单() { useful = FormUseful.新增 });
            }
        }

        private void uiImageButton4_Click(object sender, EventArgs e)
        {
            if (AccessBLL.CheckAccess("新增来货退卷单"))
            {
                MainForm.mainform.AddMidForm(new 来货退仓单() { Useful = FormUseful.新增 });
            }
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            CheckTab(new 来货入库() { Text = "单布进仓列表" });
        }

        private void linkLabel4_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            CheckTab(new 流程卡查询());
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            CheckTab(new 销售发货列表() { Text = "成品出仓列表" });
        }

        private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            CheckTab(new 生产退仓查询() { Text = "单布退仓列表" });
        }

        private void uiImageButton5_Click(object sender, EventArgs e)
        {
            if (AccessBLL.CheckAccess("销售预出库"))
            {
                MainForm.mainform.AddMidForm(new 销售预出库() { useful = FormUseful.新增 });
            }
        }

        private void linkLabel5_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            CheckTab(new 打卷报表());
        }

        private void uiSymbolButton1_Click(object sender, EventArgs e)
        {
            navBarControl1.Width = navBarControl1.Width == 159 ? 0 : 159;
        }
    }
}
